package cn.longg.mapper;

import cn.longg.entity.Meeting;
import org.apache.ibatis.annotations.Param;
import org.springframework.util.StringUtils;

import java.util.List;

public class MeetingMapperSqlProvider {

    public String selectByPage(Meeting meeting){
        StringBuilder sb = new StringBuilder();
        sb.append("select * from meeting where 1=1 ");
        if(!StringUtils.isEmpty(meeting.getTitle())){
            sb.append("and title like concat('%',#{title},'%') ");
        }
        if(!StringUtils.isEmpty(meeting.getStatus())){
            sb.append("and status = #{status} ");
        }
        return sb.toString();
    }
    public String updateBegin(@Param("beginMeeting") List<Integer> beginMeeting){
        StringBuilder sb = new StringBuilder();
        sb.append("update meeting set status = 1 where id in (");
        for (int i = 0; i < beginMeeting.size(); i++) {
            sb.append("#{beginMeeting[" + i + "]},");
        }
        sb.deleteCharAt(sb.lastIndexOf(","));
        sb.append(")");
        return sb.toString();
    }

    public String updateFinish(@Param("finishMeeting") List<Integer> finishMeeting){
        StringBuilder sb = new StringBuilder();
        sb.append("update meeting set status = 2 where id in (");
        for (int i = 0; i < finishMeeting.size(); i++) {
            sb.append("#{finishMeeting[" + i + "]},");
        }
        sb.deleteCharAt(sb.lastIndexOf(","));
        sb.append(")");
        return sb.toString();
    }
}
